﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Approval.aspx.cs" Inherits="CentralOffice.WebClient.Tasks.Approval" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>申请审批</title>
    <link rel="stylesheet" type="text/css" href="../theme/2/style.css" />
    <script src="../inc/js/ccorrect_btn.js" type="text/javascript"></script>
    <script src="../inc/js/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
</head>
<body class="bodycolor" topmargin="5">
<table border="0" width="100%" cellspacing="0" cellpadding="3" class="small">
  <tr>
    <td class="Big"><img src="../images/sys_config.gif" WIDTH="22" HEIGHT="20" align="absmiddle"><span class="big3"> 申请信息</span>
    </td>
  </tr>
</table>

    <form id="form1" runat="server">
    <ajaxToolkit:ToolkitScriptManager runat="server" ID="sm" />
<table class="TableBlock wrapper "  width="90%">
   <tr width=100%>
       <td nowrap class="TableData" style="width:120px;">申请：</td><td nowrap class="TableData fontBold" colspan="3"><asp:Literal ID="lblName" runat="server"></asp:Literal></td>
   </tr>
   
   <tr>
    <td nowrap class="TableData" style="width:120px;">申请人：</td><td nowrap class="TableData fontBold"><asp:Literal ID="lblApplicant" runat="server"></asp:Literal></td>
    <td nowrap class="TableData" style="width:120px;">申请日期：</td><td nowrap class="TableData fontBold"><asp:Literal ID="lblDateOfApplication" runat="server"></asp:Literal></td>
   </tr>

   <tr><td nowrap class="TableData">审批内容：</td><td nowrap class="TableData fontBold" colspan="3"><asp:Literal ID="lblApprovalContent" runat="server"></asp:Literal></td></tr>
   <tr>
       <td nowrap class="TableData">审批结果：</td><td nowrap class="TableData fontBold"><asp:Literal ID="lblResultApproved" runat="server"></asp:Literal></td>
       <td nowrap class="TableData">审批日期：</td><td nowrap class="TableData fontBold"><asp:Literal ID="lblDateApproved" runat="server"></asp:Literal></td>
   </tr>
   <tr>
       <td nowrap class="TableData">上步审批内容：</td><td nowrap class="TableData fontBold"><asp:Literal ID="lblPreviousContentText" runat="server"></asp:Literal></td>
        <td nowrap class="TableData">上步审批日期：</td><td nowrap class="TableData fontBold"><asp:Literal ID="lblPreviousDateApproved" runat="server"></asp:Literal></td>
   </tr>
   <tr>
       <td nowrap class="TableData">上步审批者：</td><td nowrap class="TableData fontBold"><asp:Literal ID="lblPreviousApprovedBy" runat="server"></asp:Literal></td>
       <td nowrap class="TableData">上步审批结果：</td><td nowrap class="TableData fontBold"><asp:Literal ID="lblPreviousResultApproved" runat="server"></asp:Literal></td>
   </tr>
   <tr>
    <td class="TableData">附件：</td><td class="TableData fontBold" colspan="3"><asp:HyperLink ID="lblAttachments" runat="server" Visible="false"></asp:HyperLink></td>
   </tr>
   
</table>

<div class=" wrapper " >
<div id="divPaymentList" style="margin-top:20px; margin-left:8px;" runat="server" visible="false"><h3>周付款计划列表</h3></div>
<huag:OAGridView  id="gvPaymentItem" runat="server" DataKeyNames="Id"  Visible="false"
        skinid="GridView" Width="90%"   EnableExport="false" 
        ShowFooter="true" ><%--EnableCheck="True" CheckBoxFieldHeaderText="是否同意" --%>
   <Columns>
       <%--<asp:CheckBoxField DataField="IsApproved" HeaderText="是否同意" />--%>
       <asp:TemplateField HeaderText="是否同意"><ItemTemplate><asp:CheckBox ID="chkIsApproved" runat="server" Checked='<%# Convert.ToBoolean(Eval("IsApproved")) %>' /></ItemTemplate></asp:TemplateField>
       <asp:BoundField DataField="Customer" HeaderText="供应商"   ReadOnly="True"/>
       <asp:BoundField DataField="Subject" HeaderText="付款内容"   ReadOnly="True"/>
       <asp:BoundField DataField="TotalDue" HeaderText="应付款" DataFormatString="{0:n2}" />
       <asp:TemplateField HeaderText="审批同意的应付款"><ItemTemplate><asp:TextBox ID="txtApprovedDue" runat="server"  Text='<%# Bind("ApprovedDue") %>'></asp:TextBox></ItemTemplate></asp:TemplateField>
       <%--<asp:BoundField DataField="ApprovedDue" HeaderText="审批同意的应付款" DataFormatString="{0:n2}" />--%>
       <%--<asp:BoundField DataField="ApprovedBy" HeaderText="审批人"  />
       <asp:BoundField DataField="ApprovedDate" HeaderText="审批日期" DataFormatString="{0:yyyy-MM-dd HH:mm:ss}" />--%>
       <huag:EnumTypeField DataField="Status" HeaderText="审批结果" CategoryName="approvalStatus" />
       <asp:BoundField DataField="Remark" HeaderText="备注" />
   </Columns>
</huag:OAGridView>
</div>


<div style="margin-top:20px; margin-left:8px;"><h3>审批：</h3></div>

<table class="TableBlock" width="90%" align="center">
    <%--<tr><td nowrap class="TableData" style="width: 113px">是否批准：</td><td nowrap class="TableData"><asp:DropDownList ID="ddlApproval" runat="server"> <asp:ListItem Text="同意" Value="1"></asp:ListItem><asp:ListItem Text="不同意" Value="0"></asp:ListItem> </asp:DropDownList></td></tr>--%>
    <tr><td nowrap class="TableData" style="width: 113px">审批意见：</td><td nowrap class="TableData"><asp:TextBox ID="txtOpinion" runat="server" CssClass="BigInput" TextMode="MultiLine" Rows="4" Columns="80" Text="同意" Width="82%"></asp:TextBox></td></tr>
    <tr><td nowrap class="TableData" style="width: 113px">附件：</td><td class="TableData"><asp:FileUpload ID="fileAttachments" runat="server" Width="82%" /></td></tr>
    <tr><td nowrap class="TableData" style="width: 113px">执行人：</td><td nowrap class="TableData"><asp:Literal ID="lblExecutor" runat="server"></asp:Literal></td></tr>
    <tr style="display: block;" id="trIsFinal"><td nowrap class="TableData" style="width: 113px">本次是否终审：</td><td nowrap class="TableData">
    <asp:CheckBox ID="chkIsFinal" runat="server" onclick="onFinalChange(this);" />
    </td></tr>
    
    <tr style="display:block;" id="trApprovalBy"><td nowrap class="TableData" style="width: 113px">下步审批者：</td><td nowrap class="TableData">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="Inline"><ContentTemplate>
    <input type="text" id="txtApprovedByReadOnly" style="width:82%" name="txtApprovedByReadOnly" class="SmallStatic" runat="server" readonly="readonly" /><asp:HiddenField ID="txtApprovedBy" runat="server" />&nbsp;<asp:LinkButton ID="btnShowPopup" CommandName="ApprovedBy" runat="server" OnClick="btnShowPopup_Click" CssClass="orgAdd">选择</asp:LinkButton>
    </ContentTemplate><Triggers><asp:AsyncPostBackTrigger ControlID="btnOK" /></Triggers></asp:UpdatePanel>&nbsp;<a id="clearApprovedBy" style="display: inline; " href="javascript:;" class="orgClear" onclick="$get('<%= txtApprovedByReadOnly.ClientID %>').value='';$get('<%= txtApprovedBy.ClientID %>').value='';">清空</a>
    <asp:HiddenField ID="txtExecutor" runat="server" />
    </td></tr>
    <tr style="display: block;" id="trApprovContentBy"><td nowrap class="TableData" style="width: 113px">下步审批内容：</td><td nowrap class="TableData" style="display:block;"><asp:TextBox ID="txtContentText" TextMode="MultiLine" Rows="4" Columns="80" runat="server" CssClass="BigInput" Width="82%" ></asp:TextBox></td></tr>
    <tr><td nowrap class="TableControl" colspan="2" align="center"><asp:Button ID="btnSave" runat="server" Text="同意" CssClass="BigButton" OnClick="btnAccept_Click" OnClientClick=" return validateClient();"  /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Button ID="Button1" runat="server" Text="不同意" CssClass="BigButton" OnClick="btnReject_Click" OnClientClick=" return confirm('您确定 　『 否决 』　本步审批吗？') ;"  /></td></tr>
</table>


<asp:Panel ID="pnlPopup" runat="server" CssClass="x-pne" style="display:none; width:460px;">
    <asp:UpdatePanel ID="updPnlDepartment" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    
    <asp:HiddenField ID="txtSelectedObject" runat="server" />
    <asp:Button id="btnShowEdit" runat="server" style="display:none" />
    <ajaxToolKit:ModalPopupExtender ID="mdlDetailView" runat="server" 
        BehaviorID="detailView" 
        TargetControlID="btnShowEdit" 
        PopupControlID="pnlPopup" 
        CancelControlID="btnClose" BackgroundCssClass="modalBackground" 
        PopupDragHandleControlID="pnlDrag" />
        
    <asp:Panel ID="pnlDrag" runat="server" CssClass="corner-bg x-pne-lt x-pne-left">
        <div class="corner-bg x-pne-rt x-pne-right">
            <div class="corner-bg x-pne-t dragTitle">
                <div class="x-pne-btn" id="Div1" onclick="$find('detailView').hide();"></div>
                <div class="x-pne-caption font dragTitle"><span>请选择:</span></div>
            </div>
        </div>
    </asp:Panel>

    <div>
    
        <div class="side-bg x-pne-l">
            <div class="side-bg x-pne-r">
                <div class="x-pne-c" style="WIDTH: 448px;">
					<div style="margin:10px;font-size:9pt;" class="wrapper">
					
<div id="div2" style="width:430px;height:300px; overflow:auto;">
<asp:TreeView ID="tvEmp" runat="server" EnableViewState="true" OnLoad="tvEmp_Load"></asp:TreeView>
</div>
                    
                    <!-- 下面是确认按钮 -->
                    <div style="width:328px; margin-top:16px;">
                        <table  style="width:100%; margin-left:40px;">
                            <tr>
                                <td>
<div class="btn-side btn-bg"></div>
<div class="btn-body btn-bg" style="background-position: 0px 168px; width: 66px"><asp:Button ID="btnOK" runat="server" Text="  确定  " CssClass="font" OnClick="btnOK_Click" /></div>
<div class="btn-side btn-bg" style="background-position: 0px 189px"></div>

                                </td>
                                <td>
<div class="btn-side btn-bg"></div>
<div class="btn-body btn-bg" style="background-position: 0px 168px; width: 66px;"><asp:Button ID="btnClose" runat="server" Text="  取消  " CssClass="font" /></div>
<div class="btn-side btn-bg" style="background-position: 0px 189px"></div>
                                </td>
                            </tr>
                        </table>
                    </div>
					</div>
                </div>
            </div>
        </div>

        <div class="corner-bg x-pne-lb x-pne-left">
            <div class="corner-bg x-pne-rb x-pne-right">
                <div class="corner-bg x-pne-b"></div>
            </div>
        </div>
        
    </div>
    
    </ContentTemplate>
    </asp:UpdatePanel>
</asp:Panel>

<asp:updateprogress id="updateProgress"  runat="server">
    <progresstemplate>
        <div id="progressBackgroundFilter"></div>
        <div id="processMessage">正在处理数据，请稍等...<br /><br /><img alt="Loading" src="../images/loading_16.gif" /></div>
    </progresstemplate>
</asp:updateprogress>



<script type="text/javascript">
    var approvedBy = "";
    var executor = "";
    function selectAll() {
        var tree = document.getElementById("<%=tvEmp.ClientID%>");
        if (typeof (tree) === "undefined" && tree === null) return;

        var checkBoxs = tree.getElementsByTagName('INPUT');
        for (var i = 0; i < checkBoxs.length; i++) {
            if (checkBoxs[i].type == "checkbox") {
                checkBoxs[i].checked = true;
            }
        }
    }

    function reverse() {
        var tree = document.getElementById("<%=tvEmp.ClientID%>");
        if (typeof (tree) === "undefined" && tree === null) return;

        var checkBoxs = tree.getElementsByTagName('INPUT');
        for (var i = 0; i < checkBoxs.length; i++) {
            if (checkBoxs[i].type == "checkbox") {
                checkBoxs[i].checked = !checkBoxs[i].checked;
            }
        }
    }

    function OnTreeNodeChecked() {
        var ele = window.event.srcElement;
        if (ele.type == 'checkbox') {
            var childrenDivID = ele.id.replace('CheckBox', 'Nodes');
            var div = document.getElementById(childrenDivID);
            if (div == null) return;
            var checkBoxs = div.getElementsByTagName('INPUT');
            for (var i = 0; i < checkBoxs.length; i++) {
                if (checkBoxs[i].type == 'checkbox')
                    checkBoxs[i].checked = ele.checked;
            }
        }
    }

    function validateClient() {
        if (!confirm("您确定 　『 同意 』　 吗？")) {
            return false;
        }
        var chkFinal = document.getElementById("chkIsFinal");
        if (chkFinal  && !chkFinal.checked) {
            if (document.getElementById('txtApprovedBy').value.indexOf(',') > 0) {
                alert('您只能一个审批者！'); 
                return false;
            }
        }
        
//        if (chkFinal.checked && document.getElementById("txtApprovedBy").value.length == 0) {
//            alert("终审必须选定执行者！");
//            return false;
//        }
        
        if (chkFinal && !chkFinal.checked && document.getElementById("txtApprovedBy").value.length == 0) {
            alert("如果本次审批为终审，请选中“本次是终审”，如果不是终审，请选择下一个审批者！");
            return false;
        }
        else {
            return true;
        }
    }

    function onFinalChange(chk) {
        if (!chk)
            return;
        var tr = chk.parentNode.parentNode;
        
        var trNextApproval = tr.nextSibling;
        var trContent = trNextApproval.nextSibling;


        if (chk.checked) {
            //trNextApproval.firstChild.innerText = "执行者：";
            trNextApproval.style.display = "none";
            trContent.style.display = "none";

//            if (approvedBy.length == 0) {
//                approvedBy = document.getElementById("txtApprovedBy").value;
//            }

//            if (document.getElementById("txtExecutor").value.length > 0) {
//                document.getElementById("txtApprovedBy").value = executor; //document.getElementById("txtExecutor").value;
//                document.getElementById("txtApprovedByReadOnly").value = executor; //document.getElementById("txtExecutor").value;
//            }
        }
        else {
            //trNextApproval.firstChild.innerText = "下步审批者："; //
            trNextApproval.style.display = "block";
            trContent.style.display = "block";

//            alert(approvedBy.length);
//            alert(approvedBy);

//            if (approvedBy.length > 1) {
//                document.getElementById("txtApprovedBy").value = approvedBy;
//                document.getElementById("txtApprovedByReadOnly").value = approvedBy;
//            }
//            else {
//                document.getElementById("txtApprovedBy").value = "";
//                document.getElementById("txtApprovedByReadOnly").value = "";
//            }
        }
    }

    //$addHandler (element, "click", clickHandler); 
    //jQuery("#<%=tvEmp.ClientID%>").click(
    //function(){
    //    alert('ss');
    //});

    Sys.Application.add_load(applicationLoadHandler);

    function applicationLoadHandler() {
        //executor = document.getElementById("txtExecutor").value;
        onFinalChange(document.getElementById("chkIsFinal"));
    }

    //input[type=checkbox]
    $(document).ready(function() {
        jQuery.each(jQuery("input:checkbox", jQuery("#<%= gvPaymentItem.ClientID %>")), function() {
            jQuery(this).bind("click", function() {

                var itemList = $get("<%= gvPaymentItem.ClientID %>");
                var rowCount = itemList ? itemList.rows.length : 0;
                if (rowCount > 0) {
                    var totalValue = parseFloat(itemList.rows.item(rowCount - 1).cells.item(4).innerText);
                    var itemOld = parseFloat(this.parentNode.parentNode.cells.item(3).innerHTML.replace(/\,/g, ""));
                    var itemValue = parseFloat(this.parentNode.parentNode.cells.item(4).firstChild.value);

                    if (this.checked) {
                        totalValue = totalValue + itemValue;
                    }
                    else {
                        this.parentNode.parentNode.cells.item(4).firstChild.value = 0;
                        totalValue = totalValue - itemValue;
                    }
                    itemList.rows.item(rowCount - 1).cells.item(4).innerHTML = "<span class='warning'>" + totalValue + "</span>";

                    var opinion = "";
                    for (var i = 1; i < rowCount - 1; i++) {
                        var chk = itemList.rows.item(i).cells.item(0).firstChild;

                        if (chk.checked) {
                            opinion += "同意给" + itemList.rows.item(i).cells.item(1).innerHTML + "付款" + itemList.rows.item(i).cells.item(4).firstChild.value + "元\r\n";
                        }
                        else {
                            opinion += "不同意给" + itemList.rows.item(i).cells.item(1).innerHTML + "付款" + itemList.rows.item(i).cells.item(4).firstChild.value + "元\r\n";
                        }
                    }
                    //alert(opinion);
                    if (opinion.length > 0) {
                        document.getElementById('<%= txtOpinion.ClientID %>').value = opinion; //.replace(/\|/g, "\r\n");
                        //$get('<%= txtOpinion.ClientID %>').innerHTML = opinion.replace(replace(/|/g, "\r\n"));
                    }
                    else {
                        document.getElementById('<%= txtOpinion.ClientID %>').value = "全部不同意";
                    }
                }
            });
        }, null);



        jQuery.each(jQuery("input:text", jQuery("#<%= gvPaymentItem.ClientID %>")), function() {
            jQuery(this).bind("blur", function() {

                var itemList = $get("<%= gvPaymentItem.ClientID %>");
                var rowCount = itemList ? itemList.rows.length : 0;

                var itemOld = parseFloat(this.parentNode.parentNode.cells.item(3).innerHTML.replace(/\,/g, ""));
                var itemValue = parseFloat(this.value);

                if (!isNum(this.value)) {
                    alert("金额的格式不正确！");
                    return false;
                }

                if (itemOld < itemValue) {
                    alert("批准的应付款不能大于申请的应付款！");
                    return false;
                }

                if (rowCount > 0) {
                    var opinion = "";
                    var totalValue = 0;
                    for (var i = 1; i < rowCount - 1; i++) {
                        var chk = itemList.rows.item(i).cells.item(0).firstChild;
                        if (chk.checked) {
                            opinion += "同意给" + itemList.rows.item(i).cells.item(1).innerHTML + "付款" + itemList.rows.item(i).cells.item(4).firstChild.value + "元\r\n";
                            totalValue += parseFloat(itemList.rows.item(i).cells.item(4).firstChild.value)
                        }
                        else {
                            opinion += "不同意给" + itemList.rows.item(i).cells.item(1).innerHTML + "付款" + itemList.rows.item(i).cells.item(4).firstChild.value + "元\r\n";
                        }
                    }

                    itemList.rows.item(rowCount - 1).cells.item(4).innerHTML = "<span class='warning'>" + totalValue + "</span>";
                    //alert(opinion);
                    if (opinion.length > 0) {
                        document.getElementById('<%= txtOpinion.ClientID %>').value = opinion; //.replace(/\|/g, "\r\n");
                        //$get('<%= txtOpinion.ClientID %>').innerHTML = opinion.replace(replace(/|/g, "\r\n"));
                    }
                    else {
                        document.getElementById('<%= txtOpinion.ClientID %>').value = "全部不同意";
                    }
                }
            });
        }, null);



    });


    var paymentList = $get("<%= gvPaymentItem.ClientID %>");

    
    var rowLength = paymentList ? paymentList.rows.length : 0;
    if (rowLength > 0) {
        //var chks = paymentList.getElementsByTagName("input");
        //chks[0].parentNode.appendChild(document.createTextNode("是否同意"));
        //chks[0].style.display = "none";
        
//        for (var i = 0; i < chks.length; i++) {
//            chks[i].checked = true;
//            //alert(chks[i].checked);
//        }
        
        
        var total = 0;
        for (var i = 1; i < rowLength - 1; i++) {

            var itemValue = paymentList.rows.item(i).cells.item(3).innerHTML;
            //alert(itemValue);
            if (itemValue && itemValue.length > 0) {
                total += parseFloat(itemValue.replace(/\,/g,""));
            }
        }
        paymentList.rows.item(rowLength - 1).cells.item(1).innerHTML = "<span class='warning'>审批同意的应付款合计：</span>";
        paymentList.rows.item(rowLength - 1).cells.item(4).innerHTML = "<span class='warning'>" + total + "</span>";
    }

</script>  
<asp:Literal ID="lblJavaScript" EnableViewState="false" runat="server"></asp:Literal>
    <asp:Literal ID="jsApproval" EnableViewState="false" runat="server"></asp:Literal>
    </form>
</body>
</html>
